/* 
 * File:   World.cpp
 * Author: nstratos
 * 
 * Created on September 19, 2012, 9:49 PM
 */

#include <iostream>
#include "Server.hpp"
//#include <string>
using namespace std;

std::vector<User*> Server::users;

Server::Server(string name) {
    this->name = name;
    this->world = new World();
    //this->users = new vector<User*>();
}

Server::Server(const Server& orig) {
    this->name = orig.name;
    this->users = orig.users;
}

Server::~Server() {
}

User* Server::createUser(string username) {
    User* user = new User(username);
    //User user(username);
    this->users.push_back(user);
    return user;
}

User* Server::createUser(std::string username, int age) {
    //User user(username, age);
    User* user = new User(username, age);
    //User* u = &user;
    //cout << "++DEBUG: " << user.getAge() << endl;
    this->users.push_back(user);
    //return this->users(this->users.size());
    //return this->users.back();
    return user;
    
}

std::vector<User*> Server::getUsers() const {
    return this->users;
}

void Server::printUsers() {
    for (int i = 0; i < this->users.size(); i++) {
        User* user = this->users[i];
        //cout << user.getUsername() << endl;
        string line = "---------------------------\n";
        cout << line;
        cout << "| Id: " << user->getId() << endl;
        cout << "| User: " << user->getUsername() << endl;
        cout << "| Age: " << user->getAge() << endl;
        cout << line;
    }
}

int Server::generateUserId() {
    int size = users.size();
    //int size = 0;
    size++;
    return size;
}

World* Server::getWorld() {
    return this->world;
}

void Server::printWelcomeMessage() {
    cout << "|------------------------------|" << endl;
    cout << "|++  Welcome to MyLittleRPG  ++|" << endl;
    cout << "|------------------------------|" << endl;
}

string Server::getName() {
    return this->name;
}
/* 
 * File:   World.hpp
 * Author: nstratos
 *
 * Created on September 19, 2012, 9:49 PM
 */

#ifndef SERVER_HPP
#define	SERVER_HPP

#include <vector>
#include "User.hpp"
#include "World.hpp"

class Server {
public:
    static std::vector<User*> users;
public:
    Server(std::string name);
    Server(const Server& orig);
    virtual ~Server();
    User* createUser(std::string username);
    User* createUser(std::string username, int age);
    std::vector<User*> getUsers() const;
    void printUsers();
    static int generateUserId();
    World* getWorld();
    void printWelcomeMessage();
    std::string getName();
private:
    World* world;
    std::string name;

};

#endif	/* WORLD_HPP */

